unit Parties;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, Grids, DBGrids, IBQuery, DicDM, ComCtrls, StdCtrls, Main;

type
  TfmParties = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    edYear: TEdit;
    Label1: TLabel;
    UpDown1: TUpDown;
    Label2: TLabel;
    edCurrentParty: TEdit;
    Label3: TLabel;
    edCurrentYear: TEdit;
    btnOk: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
    procedure FormShow(Sender: TObject);
    procedure btnOkClick(Sender: TObject);
  private
    { Private declarations }
    FQuery: TIBQuery;
    FYear: integer;
    procedure DisplayData;
  public
    { Public declarations }
  end;

var
  fmParties: TfmParties;

implementation
uses Party;
{$R *.DFM}

procedure TfmParties.FormCreate(Sender: TObject);
begin
  FQuery := dmDic.qParties;
  DataSource1.DataSet := FQuery;
  FYear := IniFile.ReadInteger('EK', 'PartyYear', 1996);
  edCurrentYear.Text := IntToStr(dmDic.CurrentYear);
  edCurrentParty.Text := IntToStr(dmDic.CurrentParty);
end;

procedure TfmParties.FormShow(Sender: TObject);
begin
  DisplayData;
end;

procedure TfmParties.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FQuery.Close;
  IniFile.WriteInteger('EK', 'PartyYear', FYear);

  Action := caFree;
end;

procedure TfmParties.btnOkClick(Sender: TObject);
begin
  dmDic.CurrentYear := StrToInt(edCurrentYear.Text);
  dmDic.CurrentParty := StrToInt(edCurrentParty.Text);
  fmMain.ShowCurrentParty;
  Close;
end;

procedure TfmParties.DisplayData;
begin
  UpDown1.Position := FYear;
  FQuery.Close;
  FQuery.ParamByName('GOD_KSU').AsInteger := FYear;
  FQuery.Open;
  {with dmDic.qParty do begin
    ParamByName('GOD_KSU').AsInteger := FYear;
  end;}
end;

procedure TfmParties.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = 27 then Close;
end;

procedure TfmParties.DBGrid1DblClick(Sender: TObject);
begin
  fmParty := TfmParty.Create(Application);
  fmParty.SetParams(FQuery.FieldByName('N_KSU').AsInteger, FYear);
  fmParty.Show;
end;

procedure TfmParties.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = 13 then DBGrid1DblClick(Self);
end;

procedure TfmParties.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
  if Button = btNext then
    FYear := FYear + 1
  else
    FYear := FYear - 1;
  DisplayData;
end;

end.
